package servlet;

import dao.Db;
import javabean.Worker;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

@WebServlet("/update")
public class UpDataOk extends GenericServlet {
    @Override
    public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
        //设置编码
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //收参
        Integer id= Integer.valueOf(req.getParameter("id"));
        String name = req.getParameter("name");
        String work = req.getParameter("work");

        Worker worker = new Worker(id,name,work);
        System.out.println("worker: = " + worker);
        Db db = new Db();
        int i = db.upDateDataOk(worker);
        System.out.println("i: = " + i);
        if (i>0){
            req.getRequestDispatcher("worker").forward(req,resp);
        }else{
            System.out.println("更新失败！");
        }
    }
}
